/*
 * Copyright (c) 2005, 2014 vacoor
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */
package org.vacoor.nothing.web.misc.license;

import java.math.BigInteger;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.RSAKeyGenParameterSpec;

public class RSAKeysGenerator {
    private static final int keysize = 512;
//    private static final int keysize = 256;

    public static void main(String[] args) throws Exception {
        KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA");
        keyPairGen.initialize(new RSAKeyGenParameterSpec(keysize, RSAKeyGenParameterSpec.F4));
        KeyPair keyPair = keyPairGen.generateKeyPair();

        BigInteger priMod = ((RSAPrivateKey) keyPair.getPrivate()).getModulus();
        BigInteger priExp = ((RSAPrivateKey) keyPair.getPrivate()).getPrivateExponent();

        BigInteger pubMod = ((RSAPublicKey) keyPair.getPublic()).getModulus();
        BigInteger pubExp = ((RSAPublicKey) keyPair.getPublic()).getPublicExponent();

        System.out.println("private static BigInteger PRIVATE_MOD = new BigInteger(\"" + priMod.toString(16) + "\", 16);");
        System.out.println("private static BigInteger PRIVATE_EXP = new BigInteger(\"" + priExp.toString(16) + "\", 16);");
        System.out.println("private static BigInteger PUBLIC_MOD = new BigInteger(\"" + pubMod.toString(16) + "\", 16);");
        System.out.println("private static BigInteger PUBLIC_EXP = new BigInteger(\"" + pubExp.toString(16) + "\", 16);");

    }
}